module.exports = app => {
    const { STRING, DATE, BIGINT, INTEGER, TEXT } = app.Sequelize;
    const sandbox = app.model.define("sandbox", {
        id: {
            type: BIGINT(11),
            autoIncrement: true,
            primaryKey: true,
            unique: true
        },
        one_key: BIGINT(11),
        two_key: BIGINT(11),
        openid: STRING(30),
        type: TEXT, // coupon:优惠券
        status: {
            type: INTEGER,
            defaultValue: 1
        },
        created_at: DATE,
        updated_at: DATE,
    }, {
        timestamps: true, // 自动维护时间戳 [ created_at、updated_at ]
        createdAt: 'created_at',
        updatedAt: 'updated_at',
        deletedAt: false, // 'deleted_at',
        paranoid: false
    });


    sandbox.associate = () => {
        app.model.ModSandbox.belongsTo(app.model.ModCoupon, {
            as: 'coupon',
            foreignKey: 'oneKey',
            targetKey: 'id'
        });
    }

    // sandbox.sync({ force: true });

    return sandbox;
};